package com.app.studyroom.mapper;

import java.util.HashMap;
import java.util.Map;

public class MessageReadStatusMapper {

    private static final Map<String, String> codeToName = new HashMap<>();
    private static final Map<String, String> nameToCode = new HashMap<>();

    static {
        // 默认映射
        codeToName.put("0", "未读");
        codeToName.put("1", "已读");

        for (Map.Entry<String, String> entry : codeToName.entrySet()) {
            nameToCode.put(entry.getValue(), entry.getKey());
        }
    }

    // ✅ 接口响应后可动态更新映射
    public static void initFromMap(Map<String, String> map) {
        codeToName.clear();
        nameToCode.clear();

        for (Map.Entry<String, String> entry : map.entrySet()) {
            codeToName.put(entry.getKey(), entry.getValue());
            nameToCode.put(entry.getValue(), entry.getKey());
        }
    }

    public static String getNameByCode(String code) {
        return codeToName.getOrDefault(code, "未知状态");
    }

    public static String getCodeByName(String name) {
        return nameToCode.getOrDefault(name, "-1");
    }

    public static Map<String, String> getCodeToNameMap() {
        return new HashMap<>(codeToName);
    }
}
